/**
 * @Description: 加载中封装
 *
 * @author: 风信子
 *
 * @date: 2022/2/14
 */
import Vue from "vue";
import loading from "./loadding.vue";

const loadingConstructor = Vue.extend(loading);
const instance = new loadingConstructor({
  el: document.createElement("div"),
});

const loadingClose = () => {
  if (Vue.prototype.$isServer) return;
  const vm = instance;
  if (vm.$el && vm.$el.parentNode) {
    vm.$el.parentNode.removeChild(vm.$el);
  }
};

const loadingOpent = () => {
  if (Vue.prototype.$isServer) return;
  const body = document.querySelector("body");
  if (body.append) {
    body.append(instance.$el);
  } else {
    body.appendChild(instance.$el);
  }
};

const aaa = {
  loadingOpent,
  loadingClose,
};

export default aaa;
